home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / FileMenu.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  14.4 KB  |  505 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Alias|Wavefront Script File
  18. // MODIFY THIS AT YOUR OWN RISK
  19. //
  20. // Creation Date:  Nov 17 1996
  21. //
  22. //  Procedure Name:
  23. //      FileMenu
  24. //
  25. //  Description:
  26. //        This procedure creates the main menubar File menu.
  27. //
  28. //  Input Arguments:
  29. //      None
  30. //
  31. //  Return Value:
  32. //      None.
  33. //
  34.  
  35. global proc forceSavePreferences()
  36. // Removed for Maya 3.0 but could still be on people's shelves
  37. {
  38.     warning ("The procedure forceSavePreferences is obsolete and is no longer supported.");
  39. }
  40.  
  41. global proc FileMenu_SaveItem()
  42. //
  43. // If the current file is named, save it.  If it
  44. // is still untitled, then bring up the Save As
  45. // dialog.
  46. //
  47. {
  48.     string $sceneName = `file -q -sceneName`;
  49.  
  50.     // Get the name of the scene File.
  51.     if ( size($sceneName) == 0 ) {
  52.         // Then the name can't be set.
  53.         projectViewer SaveAs;
  54.     // bug fix 89970 file save
  55.     } else if ((`file -q -amf`) || (`file -q -ex` == 0)) {
  56.         int $incrementalSave = false;
  57.         if(`optionVar -exists isIncrementalSaveEnabled`)
  58.             $incrementalSave = `optionVar -q isIncrementalSaveEnabled`;
  59.         if ( $incrementalSave ) {
  60.             // Save the scene using the Incremental Save feature.
  61.             //
  62.             incrementalSaveScene;
  63.         } else {
  64.             string $cmd = "file -save";
  65.             evalEcho($cmd);
  66.         }
  67.     } else {
  68.         warning ("No changes to save.");
  69.     }
  70. }
  71.  
  72.  
  73. global proc buildRecentProjectsMenu()
  74. {
  75.     string $RecentProjectsList[];
  76.     string $localList[];
  77.     string $name;
  78.     int $i;
  79.     int $nNumItems;
  80.     int $nNumItemsToBeRemoved;
  81.     int $RecentProjectsMaxSize;
  82.  
  83.     if (!`optionVar -exists "RecentProjectsList"`) return;
  84.  
  85.     // get the list
  86.     $RecentProjectsList = `optionVar -q "RecentProjectsList"`;
  87.     $nNumItems = size($RecentProjectsList);
  88.     $RecentProjectsMaxSize = `optionVar -q "RecentProjectsMaxSize"`;
  89.  
  90.     // check if there are too many items in the list
  91.     if ($RecentProjectsMaxSize < $nNumItems)
  92.     {
  93.         //if so, truncate the list
  94.         $nNumItemsToBeRemoved = $nNumItems - $RecentProjectsMaxSize;
  95.  
  96.         //Begin removing items from the head of the array (least recent project in the list)
  97.         for ($i = 0; $i < $nNumItemsToBeRemoved; $i++)
  98.         {
  99.             optionVar -rfa "RecentProjectsList" 0;
  100.         }
  101.         $RecentProjectsList = `optionVar -q "RecentProjectsList"`;
  102.         $nNumItems = size($RecentProjectsList);
  103.     }
  104.  
  105.     // first, check if we are the same.
  106.     $localList = `menu -q -itemArray FileMenuRecentProjectItems`;
  107.     if ($nNumItems == size($localList))
  108.     {
  109.         for ($i = 0; $i < $nNumItems; $i++)
  110.         {
  111.             if ($localList[$i] != $RecentProjectsList[$nNumItems-$i-1])
  112.                 break;
  113.         }
  114.         if ($i == $nNumItems) return;
  115.     }
  116.  
  117.     // we are not the same, so start over.
  118.     menu -e -deleteAllItems  FileMenuRecentProjectItems;
  119.     setParent -menu FileMenuRecentProjectItems;
  120.     for ($i = 0; $i < $nNumItems; $i++)
  121.     {
  122.         string $cmd = "setProject \"" + $RecentProjectsList[$nNumItems-$i-1] + "\"";
  123.         if (`about -nt`)
  124.         {
  125.             $name = unconvert ($RecentProjectsList[$nNumItems-$i-1]);
  126.             menuItem -l $name -c $cmd;
  127.         }
  128.         else
  129.         {
  130.             menuItem -l $RecentProjectsList[$nNumItems-$i-1] -c $cmd;
  131.         }
  132.     }
  133. }
  134.  
  135. global proc  buildRecentFileMenu()
  136. {
  137.     string $RecentFilesList[];
  138.     string $RecentFilesTypeList[];
  139.     string $localList[];
  140.     string $name;
  141.     int $i;
  142.     int $nNumItems;
  143.     int $nNumItemsToBeRemoved;
  144.     int $RecentFilesMaxSize;
  145.  
  146.     if (!`optionVar -exists "RecentFilesList"`) return;
  147.  
  148.     // get the list
  149.     $RecentFilesList = `optionVar -q "RecentFilesList"`;
  150.     $nNumItems = size($RecentFilesList);
  151.     $RecentFilesMaxSize = `optionVar -q "RecentFilesMaxSize"`;
  152.  
  153.     // check if there are too many items in the list
  154.     if ($RecentFilesMaxSize < $nNumItems)
  155.     {
  156.         //if so, truncate the list
  157.         $nNumItemsToBeRemoved = $nNumItems - $RecentFilesMaxSize;
  158.  
  159.         //Begin removing items from the head of the array (least recent file in the list)
  160.         for ($i = 0; $i < $nNumItemsToBeRemoved; $i++)
  161.         {
  162.             optionVar -rfa "RecentFilesList" 0;
  163.         }
  164.         $RecentFilesList = `optionVar -q "RecentFilesList"`;
  165.         $nNumItems = size($RecentFilesList);
  166.     }
  167.  
  168.     // The RecentFilesTypeList optionVar may not exist since it was
  169.     // added after the RecentFilesList optionVar. If it doesn't exist,
  170.     // we create it and initialize it with a guest at the file type
  171.     if ($nNumItems > 0 )
  172.     {
  173.         if ( !`optionVar -exists "RecentFilesTypeList"`)
  174.         {
  175.             initRecentFilesTypeList( $RecentFilesList );
  176.         }
  177.         $RecentFilesTypeList = `optionVar -q "RecentFilesTypeList"`;
  178.     }
  179.         
  180.  
  181.     // first, check if we are the same.
  182.     $localList = `menu -q -itemArray FileMenuRecentFileItems`;
  183.     if ($nNumItems == size($localList))
  184.     {
  185.         for ($i = 0; $i < $nNumItems; $i++)
  186.         {
  187.             if ($localList[$i] != $RecentFilesList[$nNumItems-$i-1])
  188.                 break;
  189.         }
  190.         if ($i == $nNumItems) return;
  191.     }
  192.  
  193.     // we are not the same, so start over.
  194.     menu -e -deleteAllItems  FileMenuRecentFileItems;
  195.     setParent -menu FileMenuRecentFileItems;
  196.     for ($i = 0; $i < $nNumItems; $i++)
  197.     {
  198.         string $cmd = "file -f -open -type \\\"" +
  199.                 $RecentFilesTypeList[$nNumItems-$i-1] + "\\\" \\\"" +
  200.                 $RecentFilesList[$nNumItems-$i-1] + "\\\";";
  201.         $cmd = $cmd + "addRecentFile(\\\"" +
  202.                 $RecentFilesList[$nNumItems-$i-1] + "\\\", \\\"" +
  203.                 $RecentFilesTypeList[$nNumItems-$i-1] + "\\\");";
  204.         $cmd = "saveChanges (\"" + $cmd + "\"); checkForUnknownNodes();";
  205.         if (`about -nt`)
  206.         {
  207.             $name = unconvert ($RecentFilesList[$nNumItems-$i-1]);
  208.             menuItem -l $name -c $cmd;
  209.         }
  210.         else
  211.         {
  212.             menuItem -l $RecentFilesList[$nNumItems-$i-1] -c $cmd;
  213.         }
  214.     }
  215. }
  216.  
  217. //
  218. //  Procedure Name:
  219. //        buildIncrementalSaveMenu
  220. //
  221. //  Description:
  222. //      Build the sub menu in the file menu that lists the recent incremental
  223. //        backups that exist for the current scene
  224. //
  225. //  Input Arguments:
  226. //    None.
  227. //
  228. //  Return Value:
  229. //    None.
  230. //
  231. global proc buildIncrementalSaveMenu() 
  232. {
  233.     string $scenePath = `file -q -sceneName`;
  234.  
  235.     if ( size( $scenePath ) == 0 ) return; 
  236.  
  237.     string $pathInfo[] = incrementalSaveProcessPath( $scenePath );
  238.     string $scenePath = $pathInfo[0];
  239.     string $sceneExtension = $pathInfo[2];
  240.     string $sceneNamePrefix = $pathInfo[3];
  241.     string $incrementDirName = $pathInfo[5] + "/";
  242.  
  243.     string $incrementDirPath = $scenePath + $incrementDirName;
  244.  
  245.     // Get a list of all files in the backup directory
  246.     //
  247.     string $existingIncrements[] = `getFileList 
  248.         -folder $incrementDirPath 
  249.         -filespec ($sceneNamePrefix + ".*" + $sceneExtension)`;
  250.  
  251.     // Make sure that they are sorted
  252.     //
  253.     $existingIncrements = sort( $existingIncrements );
  254.  
  255.     int $numIncrementals = `optionVar -q "RecentBackupsMaxSize"`;
  256.  
  257.     // Build the menu
  258.     //
  259.     int $last = size( $existingIncrements );
  260.     int $first = max( 0, $last - $numIncrementals );
  261.     menu -e -deleteAllItems FileMenuRecentBackupItems;
  262.     setParent -menu FileMenuRecentBackupItems;
  263.     for ( $i = $first; $i < $last; $i++ ) {
  264.         string $cmd = "file -f -open \"" + $incrementDirPath + $existingIncrements[$i] + "\"";
  265.         string $sceneName = `match "[^/]+$" $existingIncrements[$i]`;
  266.         menuItem -l $sceneName -c $cmd;
  267.     }
  268. }
  269.  
  270. //
  271. //  Procedure Name:
  272. //        hasIncrementalSaves
  273. //
  274. //  Description:
  275. //      Returns true if the current file has some automatic backups
  276. //
  277. //  Input Arguments:
  278. //        None.
  279. //
  280. //  Return Value:
  281. //        None.
  282. //
  283. global proc int hasIncrementalSaves() 
  284. {
  285.     int $result = 0;
  286.  
  287.     string $scenePath = `file -q -sceneName`;
  288.  
  289.     if ( size( $scenePath ) > 0 ) { 
  290.         string $pathInfo[] = incrementalSaveProcessPath( $scenePath );
  291.         string $scenePath = $pathInfo[0];
  292.         string $sceneExtension = $pathInfo[2];
  293.         string $sceneNamePrefix = $pathInfo[3];
  294.         string $incrementDirName = $pathInfo[5] + "/";
  295.         
  296.         string $incrementDirPath = $scenePath + $incrementDirName;
  297.  
  298.         // Get a list of all files in the backup directory
  299.         //
  300.         string $existingIncrements[] = `getFileList 
  301.             -folder $incrementDirPath 
  302.             -filespec ($sceneNamePrefix + ".*" + $sceneExtension)`;
  303.  
  304.         $result = ( size( $existingIncrements ) > 0 );
  305.     }
  306.  
  307.     return $result;
  308. }
  309.  
  310. //
  311. //  Procedure Name:
  312. //        checkMainFileMenu
  313. //
  314. //  Description:
  315. //      Disables or enables the recent files, backups, and projects
  316. //        menus depending on whether they have contents.
  317. //
  318. //  Input Arguments:
  319. //        None.
  320. //
  321. //  Return Value:
  322. //        None.
  323. //
  324. global proc checkMainFileMenu()
  325. {
  326.  
  327.     int $enable = false;
  328.     if (`optionVar -exists "RecentFilesList"`)
  329.     {
  330.         if (`optionVar -arraySize "RecentFilesList"` > 0) $enable = 1;        
  331.     }
  332.     menuItem -e -enable $enable FileMenuRecentFileItems;
  333.     
  334.     $enable = hasIncrementalSaves();
  335.     menuItem -e -enable $enable FileMenuRecentBackupItems;
  336.  
  337.     $enable = false;
  338.     if (`optionVar -exists "RecentProjectsList"`)
  339.     {
  340.         if (`optionVar -arraySize "RecentProjectsList"` > 0) {
  341.             $enable = true;        
  342.         }
  343.     }
  344.     menuItem -e -enable $enable FileMenuRecentProjectItems;
  345. }
  346.  
  347.  
  348. {
  349.     global string $gMainFileMenu;
  350.     global string $gMainWindow;
  351.  
  352.     int $dimWhenNoSelect = 0;
  353.     menu -p $gMainWindow -l "File"
  354.         -allowOptionBoxes true -tearOff true 
  355.         -postMenuCommand checkMainFileMenu
  356.         -familyImage "menuIconFile.xpm" $gMainFileMenu;
  357.         
  358.         menuItem -label "New Scene" 
  359.             -annotation "New Scene: Create a new scene"
  360.             -command ("NewScene") newProject;
  361.  
  362.         menuItem -label "Open Scene..." 
  363.             -annotation "Open Scene: Open a scene"
  364.             -command ("OpenScene") openProject;
  365.             menuItem -optionBox true 
  366.                 -annotation "Open Scene Option Box"
  367.                 -label "Open Scene Option Box"
  368.                 -command ("OpenSceneOptions")
  369.                 openFileOptions;
  370.  
  371.         menuItem -divider true;
  372.  
  373.         menuItem -label "Save Scene" 
  374.             -annotation "Save Scene: Save the current scene"
  375.             -command ("SaveScene") saveItem;
  376.             menuItem -optionBox true 
  377.                 -annotation "Save Scene Option Box"
  378.                 -label "Save Scene Option Box"
  379.                 -command ("SaveSceneOptions") 
  380.                 saveOptions;
  381.  
  382.         menuItem -l "Save Scene As..." 
  383.             -annotation "Save Scene As: Save the current scene under a new name or export all"
  384.             -command ("SaveSceneAs") saveAsItem;
  385.             menuItem -optionBox true 
  386.                 -annotation "Save Scene As Option Box"
  387.                 -label "Save Scene As Option Box"
  388.                 -command ("SaveSceneAsOptions") 
  389.                 saveAsOptions;
  390.  
  391.  
  392.         menuItem -ecr false -label "Save Preferences" 
  393.             -annotation "Save Preferences: Save the current preferences"
  394.             -command ("SavePreferences");
  395.  
  396.         menuItem -divider true;
  397.         
  398.         menuItem -l "Optimize Scene Size"
  399.             -annotation "Optimize Scene Size: Remove unused items"
  400.             -command ("OptimizeScene") cleanUpProject;
  401.             menuItem -optionBox true
  402.                 -annotation "Optimize Scene Size Option Box"
  403.                 -label "Optimize Scene Size Option Box"
  404.                 -command ("OptimizeSceneOptions") cleanUpSceneOptions;
  405.  
  406.         menuItem -divider true;
  407.  
  408.         menuItem -label "Import..." 
  409.             -annotation "Import: Add the file to the current scene"
  410.             -command ("Import") importFileItem;
  411.             menuItem -optionBox true 
  412.                 -annotation "Import Option Box"
  413.                 -label "Import Option Box"
  414.                 -command ("ImportOptions") 
  415.                 importFileOptions;
  416.  
  417.         menuItem -label "Export All..." 
  418.             -annotation "Export All: Export entire scene (including contents of all references) into one file"
  419.             -command ("Export") exportAllFileItem;
  420.             menuItem -optionBox true 
  421.                 -annotation "Export All Option Box"
  422.                 -label "Export All Option Box"
  423.                 -command ("ExportOptions") 
  424.                 exportAllFileOptions;
  425.  
  426.         menuItem -label "Export Selection..." 
  427.             -annotation "Export Selection: Export selected objects (and related info) to a new file"
  428.             -command ("ExportSelection") exportActiveFileItem;
  429.             menuItem -optionBox true 
  430.                 -annotation "Export Selection Option Box"
  431.                 -label "Export Selection Option Box"
  432.                 -command ("ExportSelectionOptions") 
  433.                 exportActiveFileOptions;
  434.             if( $dimWhenNoSelect )
  435.                 dimWhen -false SomethingSelected exportActiveFileItem;
  436.         
  437.         menuItem -divider true;
  438.  
  439.         menuItem -label "Create Reference..." 
  440.             -annotation "Create Reference: Create a reference"
  441.             -command ("CreateReference") referenceFileItem;
  442.             menuItem -optionBox true 
  443.                 -annotation "Create Reference Option Box"
  444.                 -label "Create Reference Option Box"
  445.                 -command ("CreateReferenceOptions")
  446.                 referenceFileOptions;
  447.  
  448.         menuItem -label "Reference Editor..." 
  449.             -annotation "Reference Editor: Edit the references for the current scene"
  450.             -command ("ReferenceEditor")
  451.             residentFileItem;
  452.  
  453.         menuItem -subMenu true -tearOff true -allowOptionBoxes false -label "Project" projectItems;
  454.             menuItem -label "New..." 
  455.                 -annotation "New Project: Create a new project and make it the current project"
  456.                 -command ("NewProject") newProjectFileItem;
  457.  
  458.             menuItem -label "Edit Current..." 
  459.                 -annotation "Edit Project: Edit the current project"
  460.                 -command ("EditProject") editProjectFileItem;
  461.  
  462.             menuItem -label "Set..." 
  463.                 -annotation "Set Project: Change the current project"
  464.                 -command ("SetProject") setProjectFileItem;
  465.  
  466.         setParent -m ..;
  467.  
  468.         menuItem -divider true;
  469.  
  470.         // add recent file and project lists
  471.         menuItem -subMenu true -l "Recent Files"
  472.           -postMenuCommand "buildRecentFileMenu" FileMenuRecentFileItems;
  473.         setParent -m ..;
  474.  
  475.         menuItem -subMenu true -l "Recent Increments" -postMenuCommand "buildIncrementalSaveMenu" FileMenuRecentBackupItems;
  476.         setParent -m ..;
  477.  
  478.         menuItem -subMenu true -l "Recent Projects" -postMenuCommand "buildRecentProjectsMenu" FileMenuRecentProjectItems;
  479.         setParent -m ..;
  480.  
  481.         if (!`about -mac`) {
  482.             menuItem -divider true;
  483.             
  484.             // Do not add any other code to the quit or you will not
  485.             // have it executed for some types of quitting - like
  486.             // quitting through the command language or by double-clicking
  487.             // the main Maya window.
  488.             //
  489.             menuItem -l "Exit" 
  490.                 -annotation "Exit: Exit Maya"
  491.                 -command ("Quit") quitItem;
  492.  
  493.             if (`about -nt`)
  494.             {
  495.                 menuItem -e -mn "O" openProject;
  496.                 menuItem -e -mn "S" saveItem;
  497.                 menuItem -e -mn "A" saveAsItem;
  498.                 menuItem -e -mn    "x" quitItem;
  499.             }
  500.         }
  501.     
  502.     setParent -m ..;
  503. }
  504.  
  505.